package com.yangyongchao.resumedownload.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.yangyongchao.resumedownload.R;
import com.yangyongchao.resumedownload.entires.FileInfo;
import com.yangyongchao.resumedownload.service.DownloadSrevice;

public class MainActivity extends AppCompatActivity {

    private TextView mTvFileName = null;
    private ProgressBar mProgressBar = null;
    private Button mBtnStop = null;
    private Button mBtnStart = null;

    public String downloadurl = "http://softdown1.hao123.com/hao123-soft-online-bcs/soft/2017_02_22_QQ8.9.exe";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTvFileName = (TextView) findViewById(R.id.tv_filename);
        mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
        mBtnStart = (Button) findViewById(R.id.btn_start);
        mBtnStop = (Button) findViewById(R.id.btn_pause);

        //创建一个文件信息对象
        final FileInfo fileInfo = new FileInfo(0,downloadurl,"QQpc版",0,0);

        //添加事件监听
        mBtnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //通过Intent传参给Srevice
                Intent intent = new Intent(MainActivity.this, DownloadSrevice.class);
                intent.setAction(DownloadSrevice.ACTION_START);
                intent.putExtra("fileInfo",fileInfo);
                //第一次启动intent的时候会创建Service
                startService(intent);
            }
        });

        mBtnStop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //通过Intent传参给Srevice
                Intent intent = new Intent(MainActivity.this, DownloadSrevice.class);
                intent.setAction(DownloadSrevice.ACTION_STOP);
                intent.putExtra("fileInfo",fileInfo);
                startService(intent);
            }
        });

    }
}

